package nowcoder.JZ52_两个链表的第一个公共结点;

import java.util.*;

/*
public class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }
}*/
public class Solution {

    /**
     * 遍历法
     *
     * @param a
     * @param b
     * @return
     */
    public ListNode FindFirstCommonNode(ListNode a, ListNode b) {
        for (ListNode h1 = a; h1 != null; h1 = h1.next) {
            for (ListNode h2 = b; h2 != null; h2 = h2.next) {
                if (h1 == h2) return h1;
            }
        }
        return null;
    }


    public class ListNode {
        int val;
        ListNode next = null;

        ListNode(int val) {
            this.val = val;
        }
    }
}
